package com.kwum.springcloud.cloud.microserviceconsumermovie.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.kwum.springcloud.cloud.microserviceconsumermovie.entity.SpringcloudUser;

/**
 * Description: 电影控制器
 * @author Kwum
 * @date 2017年6月30日 下午3:13:01
 * @version 1.0
 */

@RestController
@RequestMapping(value = "springcloud", produces="application/json;charset=UTF-8")
public class MovieController {

    @Autowired
    private RestTemplate restTemplate;
    
    /**
     * 用户服务消费者
     * 用于请求用户服务，根据显示对应的用户
     * @param id 用户id
     * @return 用户对象
     * @author kwum
     */
    @GetMapping("user/{id}")
    public SpringcloudUser selectUserById(@PathVariable Integer id){
        return (SpringcloudUser) restTemplate.getForObject("http://localhost:8081/springcloud/user/" + id, SpringcloudUser.class);
    }
}
